.TH std::priority_queue::empty 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::priority_queue::empty \- std::priority_queue::empty

.SH Synopsis
   bool empty() const;                \fI(until C++20)\fP
   [[nodiscard]] bool empty() const;  \fI(since C++20)\fP

   Checks if the underlying container has no elements. Equivalent to return c.empty();.

.SH Parameters

   \fI(none)\fP

.SH Return value

   true if the underlying container is empty, false otherwise.

.SH Complexity

   Constant.

.SH Example


// Run this code

 #include <algorithm>
 #include <iostream>
 #include <queue>

 int main()
 {
     std::cout << std::boolalpha;

     std::priority_queue<int> queue;

     std::cout << "Initially, queue.empty(): " << queue.empty() << '\\n';

     queue.push(42);
     std::cout << "After adding elements, queue.empty(): " << queue.empty() << '\\n';
 }

.SH Output:

 Initially, queue.empty(): true
 After adding elements, queue.empty(): false

.SH See also

   size    returns the number of elements
           \fI(public member function)\fP
   empty   checks whether the container is empty
   \fI(C++17)\fP \fI(function template)\fP
